package morenoapp.components.common.table.renderer;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import morenoapp.model.data.MorenoRespondentFace;
import morenoapp.util.MorenoUtil;

/**
 * 
 * @author dmitry.mamonov
 */
public class NameTableCellRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        if (value instanceof MorenoRespondentFace) {
            MorenoRespondentFace respondentFace = (MorenoRespondentFace) value;
            if (!respondentFace.getName().isEmpty()){
                String valueText = "<html>"+MorenoUtil.wrapTextWithColor(respondentFace.getSex().getColor(),String.valueOf(value)); //NOI18N
                this.setText(valueText);
                this.setToolTipText(valueText);
            } else {
                this.setText("");
                this.setToolTipText(null);
            }
        } else {
            this.setText("");
            this.setToolTipText(null);
        }

        return this;
    }
}